package Concurrency2.Chapter01_Base;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * Instruction：
 * Author：@author MaLi
 */
public class T02_Callable {
    public static void main(String[] args) {
        //1, 创建FutureTask
        FutureTask<String> task = new FutureTask<>(new SomeCallable());
        //2, 创建Thread
        Thread thread = new Thread(task);
        //3, 启动Thread
        thread.start();
        try {
            //4, 获取线程执行的结果
            task.get();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private static class SomeCallable implements Callable<String> {
        @Override
        public String call() throws Exception {
            TimeUnit.SECONDS.sleep(2);
            return "some callable";
        }
    }
}

